import { requestClient } from '#/api/request';

function objectToQueryString(obj) {
  return Object.entries(obj)
    .filter(
      ([_, value]) => value !== null && value !== undefined && value !== '',
    ) // 过滤掉空值或未定义值
    .map(
      ([key, value]) =>
        `${encodeURIComponent(key)}=${encodeURIComponent(value)}`,
    ) // 编码并拼接键值对
    .join('&'); // 使用&连接所有的键值对
}
/**
 * 字典查询
 */
export async function queryDictApi(data: any) {
  const url = objectToQueryString(data);
  return requestClient.post(`/dataDictionary/list?${url}`);
}

/**
 * 字典添加
 */
export async function addOrSaveDict(data: any) {
  return requestClient.post('/dataDictionary/save', data);
}
/**
 *
 * @param data 删除
 * @returns
 */
export async function deleteDict(id: any) {
  return requestClient.delete(`/dataDictionary/delete/${id}`);
}
